/**
 * Created by seeker910 on 2017/4/7.
 * @description 对话框 
 */
Rsd.define('Rsd.container.Dialog', {
    extend: 'Rsd.container.Component',
    xtype: 'dialog',
    headerTagName:'nobr',
    cls: 'x-dialog',  
    headerCls: 'x-d-header',
    bodyCls:'x-d-body',
    /** 
     * @description 可拖动
     * */ 
    draggable: true,
    /**
     * @description 是否显示关闭按钮
     */
    closeBtn: true,
    maxBtn: true,
    minBtn: true,
    "width": '100%',
    "height": 300,
    /**
     * @description 页面展示后自动加载数据
     */
    autoLoad:true,
    "style":{overflow:'hidden'}, 
    overflow:'auto',
    title:'无标题',
    isDialog:true,
    modular:true,
    floating:true,
    header:{
        space:0, 
        height: 45, 
        cls: 'x-d-header',
        "style":{
            color:'#ffffff',
            minHeight:45
        }
    },
     /**
     * 
     * @description 当前页面的menu
     */
    //menu:null,
    /**
     * 
     */
    listeners:{
        'dragstart':  {
            element:'dom',
            fn:function (sender,event) {
                event.dataTransfer.setData('Text',Rsd.toString({cmd:'move',pageX:event.pageX||event.clientX,pageY:event.pageY||event.clientY}));
            }
        }
    },
    /**
     * 
     * @param {*} config 
     */
    constructor: function Dialog(config) {

        config = config || {};
        this.apply(config); 
    },

    /**
     * @description 参数格式： (parent),(animate,speed), (parent,x, y), (parent,x, y,animate), (parent,x, y,animate,speed)
    *  @description 展示页面，指定x，y值可以提高页面加载速度；页面展示后自动加载数据（autoLoad==true）。
     * @param {*} parent 
     * @param {*} x 
     * @param {*} y 
     * @param {*} animate 
     * @param {*} speed 
     */
    showDialog:function showDialog(parent,position,animate,speed,callback){

        var _parent = parent;
        var _position = position; 
        var _animate = animate;
        var _speed = arguments.length == 0?400:speed;
        var _callback = callback;
        if(arguments.length == 2)
        {
            _animate = arguments[0];
            _speed = arguments[1];
        }
        if(arguments.length == 4)
        {
            _parent = arguments[0];
            _position = arguments[1]; 
            _animate = arguments[2];
            _speed =arguments[3];
        }
        if(arguments.length == 5)
        {
            _parent = arguments[0];
            _position = arguments[1]; 
            _animate = arguments[2];
            _speed =arguments[3];
        }
        this.callParent(_parent, _position,_animate,_speed,_callback);

        if(this.autoLoad && !this.isLoaded)
        {
            var me = this;
            setTimeout(function () {
                me.funApplyByIOC('load');
                me.isLoaded = true;
            },10);

        }
        if(Rsd.Logger)
        {
            Rsd.Logger.pv(this.$className,this.Title);
        }
        return this;
    },
    /**
     * @description 在页面右侧打开
     */
    showDialogOnRight:function showDialogOnRight(parent)
    {
        this.header.style = this.header.style||{};
        this.header.style.backgroundColor = '#0b2957ba';
        this.header.style.color = '#000';
        this.style.maxHeight = '100%';
        this.style.borderRadius = '0px';
        this.showDialog(parent||document.body,{right:0-this.width,top:0},{right:0,top:0},500);
        return this;
    },
    /**
     * @description 在页面左侧打开
     */
    showDialogOnLeft:function showDialogOnLeft(parent)
    {
        this.showDialog(parent||document.body,{left:0-this.width,top:0},{left:0,top:0},500);
        return this;
    },
    /**
     * @description 加载页面数据
     * @param {*} callback  回调函数
     * @returns 
     */
    load:function load(callback) {

        if(callback)
        {
            callback.call(this);
        }
        return this;
    }
    
},function(type) {
     //menu
     var _menuGetter = function () {

        return this.__menu||{};
    };
    var _menuSetter = function (menu) {

        this.__menu = menu;
    }

    this.defineProperty(type, "menu", _menuGetter, _menuSetter, true);
});
